<?php
//Load the page we are requesting.

if (!isset($data))
{
	$data = '';
}

$content = $tvtunes->load_content($pagename, $data);
if (is_array($options))
{
	//Add the header variable to an array.
	$page = $tvtunes->load_template('template');
	
	//Page Title.
	if (isset($options['title']))
	{
		$title = $options['title'];
	}
	else
	{
		$title = 'Undefined';
	}
	
	//Page Description.
	if (isset($options['description']))
	{
		$description = $options['description'];
	}
	else
	{
		$description = 'TV Theme music and songs from 7,856 different television shows. Listen to them all in MP3 format.';
	}
	
	//Page Keywords
	if (isset($options['keywords']))
	{
		$keywords = $options['keywords'];
	}
	else
	{
		$keywords = 'TV Theme music, tv theme songs, television songs, tv tunes, themes, theme songs, tv shows, tv music, television tunes, televisiontunes, tvsongs, jayzoo, mp3 tv music, theme music"';
	}
	
	//Page Keywords
	if (defined('ABS_URL'))
	{
		$base_url = constant('ABS_URL');
	}
	else
	{
		$base_url = $_SERVER['SERVER_NAME'];
	}
	
	//Left image
	if (isset($options['leftimage']))
	{
		if ($options['leftimage'] != '')
		{
			$leftimage = '<img src="images/' . $options['leftimage'] . '" alt="Television Tunes" />';
		}
		else
		{
			$leftimage = '';
		}
		
		if (isset($options['leftside']))
		{
			$leftside = $options['leftside'];
		}
		else
		{
			$leftside = '';
		}
		
		$leftimage = '<td width="42%" align="center" valign="top">' . $leftside . '</td>';
	}
	else
	{
		$leftimage = '';
	}
	
	//Do the replacements now that we have our variables set.
	$page = str_replace('{page_title}', $title, $page);
	$page = str_replace('{page_description}', $description, $page);
	$page = str_replace('{page_keywords}', $keywords, $page);
	$page = str_replace('{base_url}', $base_url, $page);
	$page = str_replace('{leftimage}', $leftimage, $page);
	$page = str_replace('{ads_leaderboard}', $tvtunes->ads_leaderboard(), $page);
	$page = str_replace('{latestNews}', $tvtunes->load_template('latestNews'), $page);
	if (isset($id_category))
	{
		$page = str_replace('{id_category}', $lin[0], $page);
	}
	else
	{
		$page = str_replace('{id_category}', '', $page);
	}
	
	if (isset($_GET['searWords']))
	{
		$page = str_replace('{searchWords}', $_GET['searWords'], $page);
	}
	else
	{
		$page = str_replace('{searchWords}', '', $page);
	}
	
	if (isset($lin))
	{
		$page = str_replace('{songtitle}', $lin[1], $page)
	}
}

//Let's do some content now.
if (isset($content))
{
	$page = str_replace('{content}', $content, $page);
	$page = str_replace('{newest_songs}', $tvtunes->newest_songs(), $page);
	$page = str_replace('{categories}', $tvtunes->blocks(), $page);
	if (isset($_GET['searWords']))
	{
		$page = str_replace('{searchWords}', $_GET['searWords'], $page);
	}
	else
	{
		$page = str_replace('{searchWords}', '', $page);
	}
}
else
{
	//No Content.
	$page = str_replace('{content}', '', $content);
}

print $page;
?>